package com.ruoyi.asms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.ruoyi.asms.domain.InspectionTask;
import com.ruoyi.asms.domain.vo.ThisWeekFaultSQLVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 巡检任务信息Mapper接口
 * 
 * @author yfkj
 * @date 2021-10-21
 */@Mapper
public interface InspectionTaskMapper extends BaseMapper<InspectionTask>
{
    /**
     * 查询巡检任务信息
     * 
     * @param inspectionTaskId 巡检任务信息主键
     * @return 巡检任务信息
     */
    public InspectionTask selectInspectionTaskByInspectionTaskId(Long inspectionTaskId);

    /**
     * 查询巡检任务信息列表
     * 
     * @param inspectionTask 巡检任务信息
     * @return 巡检任务信息集合
     */
    public List<InspectionTask> selectInspectionTaskList(InspectionTask inspectionTask);

    /**
     * 新增巡检任务信息
     * 
     * @param inspectionTask 巡检任务信息
     * @return 结果
     */
    public int insertInspectionTask(InspectionTask inspectionTask);

    /**
     * 修改巡检任务信息
     * 
     * @param inspectionTask 巡检任务信息
     * @return 结果
     */
    public int updateInspectionTask(InspectionTask inspectionTask);

    /**
     * 删除巡检任务信息
     * 
     * @param inspectionTaskId 巡检任务信息主键
     * @return 结果
     */
    public int deleteInspectionTaskByInspectionTaskId(Long inspectionTaskId);

    /**
     * 批量删除巡检任务信息
     * 
     * @param inspectionTaskIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteInspectionTaskByInspectionTaskIds(Long[] inspectionTaskIds);

    @Select("SELECT " +
            "count(*) AS num, " +
            "FROM_UNIXTIME(create_time / 1000, '%w') AS weekday " +
            "FROM " +
            "inspection_task " +
            "WHERE " +
            "maintenance_dept_id = #{mDeptId} " +
            "AND status = 3 " +
            "AND create_time >= #{startTime} " +
            "AND create_time <= #{endTime} " +
            "GROUP BY " +
            "weekday;")
    List<ThisWeekFaultSQLVo> getOneWeekInspectionNum(@Param("startTime") Long startTime, @Param("endTime") Long endTime,
                                                     @Param("mDeptId") Long mDeptId);
}
